/**
 * 将导入的excel '!ref' 工作范围转化为总列数、总行数
 * @param ref 
 * @returns  { numRows, numColumns } numRows总行数 numColumns总列数
 */
export const convertRefToRowsAndColumns = (ref: any):{} => {
  const range = ref.split(':');
  const startCell = range[0];
  const endCell = range[1];

  const startColumn = startCell.match(/[A-Z]+/)[0];
  const endColumn = endCell.match(/[A-Z]+/)[0];

  const startRow = parseInt(startCell.match(/\d+/)[0]);
  const endRow = parseInt(endCell.match(/\d+/)[0]);

  const numRows = endRow - startRow + 1;
  const numColumns = columnToNumber(endColumn) - columnToNumber(startColumn) + 1;

  return { numRows, numColumns };
}

/**
 * 字母坐标转数字 AA->27 BA->53
 * 如果要A->0 BA->52 AA->26 , return number-1即可
 * @param column 
 * @returns 
 */
export const columnToNumber = (column: string) => {
  let number = 0;
  for (let i = 0; i < column.length; i++) {
    number = number * 26 + column.charCodeAt(i) - 'A'.charCodeAt(0) + 1;
  }
  return number;
}

